import React, { Component } from 'react'

class CounterButton extends Component {
  render() {
    const { onClick } = this.props
    return (
      <button onClick={() => onClick()}>+1</button>
    )
  }
}



export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0,
    }
  }
  render() {
    return (
      <div>
        <h2>当前计数：{this.state.count}</h2>
        <CounterButton onClick={() => this.incrementCount()}></CounterButton>
      </div>
    )
  }
  incrementCount() {
    this.setState({
      count: this.state.count + 1
    })
  }
}
